import { LoginResult } from "@/types/employee";
import { defineStore } from "pinia";
import { ref } from "vue";

export const useUserStore = defineStore('user', () => {
  const user = ref({} as LoginResult)
  const rule = ref('')

  const login = (value: LoginResult) => {
    user.value = value
    rule.value = value.role ? value.role : 'user'
  }
  const logout = () => {
    localStorage.clear()
    user.value = {} as LoginResult
    rule.value = ''
  }
  return {
    user,
    rule,
    login,
    logout
  }
}, { persist: true })